package com.gitee.lw114514.tliasweb.service.impl;

import com.gitee.lw114514.tliasweb.mapper.ClazzMapper;
import com.gitee.lw114514.tliasweb.pojo.Clazz;
import com.gitee.lw114514.tliasweb.pojo.ClazzQueryParam;
import com.gitee.lw114514.tliasweb.pojo.PageResult;
import com.gitee.lw114514.tliasweb.service.ClazzsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class ClazzsServiceImpl implements ClazzsService {
    @Autowired
    private ClazzMapper clazzMapper;

    /*
     * 分页查询班级信息
     */
    @Override
    public PageResult<Clazz> list(ClazzQueryParam clazzQueryParam) {
        //1.设置分页参数
        log.info("分页查询班级信息:{}", clazzQueryParam);
        PageHelper.startPage(clazzQueryParam.getPage(), clazzQueryParam.getPageSize());

        //2.调用mapper接口查询结果列表
        List<Clazz> rows = clazzMapper.list(clazzQueryParam);

        //3.封装结果成{"total:"xx,"rows":[{...}]}列表并返回
        Page<Clazz> p = (Page<Clazz>) rows;
        PageResult<Clazz> pageResult = new PageResult<>((int) p.getTotal(), p.getResult());
        return pageResult;
    }

    @Override
    public List<Clazz> listAll() {
        //调用mapper接口查询结果列表
        return clazzMapper.listAll();
    }
}
